package com.hunk.core.auth.repository;

import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.hunk.core.auth.entity.Role;

/**
 * Description :<br>
 *  Data Access Object Interface
 * @author HunkDeng
 * @since 2013-4-27
 */
@Repository
public interface RoleRepository extends JpaRepository<Role, String>, JpaSpecificationExecutor<Role> {
	public abstract Role findByRoleName(String roleName);	
	@Query("select count(r.id) from Role r where r.parentRole.id = :id")
	public Long countChildren(@Param("id")String id);	
	public final static Sort defaultSort = new Sort(new Sort.Order(Direction.ASC, "roleName"));
}
